<template>
<div>

  <el-container>
    <el-header>
      <div>
        <img src="../assets/logo.png" height="30px;"></img>
        权限管理系统
      </div>
      <div>
        <el-dropdown  style="right: auto" @command="handleCommand">
  <span class="el-dropdown-link">
    {{ loginName }}<i class="el-icon-arrow-down el-icon--right"></i>
  </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item  command="update">修改用户</el-dropdown-item>
            <el-dropdown-item  command="logout">退出</el-dropdown-item>

          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px" height="400px">
        <el-menu :default-active="this.$route.path" :default-openeds="['1']" class="el-menu-vertical-demo" router >
          <el-submenu index="1" v-for="m in menus" >
            <template slot="title">
              <i class="el-icon-location"></i>
              <span slot="title">{{m.name}}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item  :index="c.path" v-for="c in m.children" >{{c.name}}</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>

        <!--路由视图-->
       <router-view/>


      </el-main>
    </el-container>
  </el-container>
</div>


</template>

<script>
export default {
  name: "IndexView",
  data(){
    return{
      def:[0,1],
      loginName:'',
      menus:[],//菜单

    }
  },created() {
    this.listMenu();
   this.loginName=  localStorage.getItem("username")
  },methods:{
    listMenu(){//获取菜单
      this.axios.get("menu/list").then(res=>{
        this.menus =res.data.data;
      })

    },
    handleCommand(command) {
      if(command=="logout"){//注销
        this.$cookies.remove("token");
        localStorage.removeItem("username");
        this.$router.push("/login");
      }
    }
  }
}
</script>

<style scoped>
.el-header {
  background-color: #00AAAA;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 24px;
}

.el-dropdown-link {
  cursor: pointer;
  color: red;
}

.el-icon-arrow-down {
  font-size: 12px;
}
</style>